package net.sunofbeach.blog.controller;

import lombok.extern.slf4j.Slf4j;
import net.sunofbeach.blog.pojo.House;
import net.sunofbeach.blog.pojo.User;
import net.sunofbeach.blog.response.ResponseResult;
import net.sunofbeach.blog.response.ResponseState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;



//@Controller
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

//    @ResponseBody
//    @RequestMapping(value = "/hello-world", method = RequestMethod.GET)
    @GetMapping("/hello-world")
    public ResponseResult HelloWorld(){
        log.info("Hello world");
        return ResponseResult.SUCCESS().setData("hello world");
    }

//    @ResponseBody
    @GetMapping("/test-json")
    public ResponseResult testJson(){
        User user = new User("特朗普",73,"male");
        House house = new House("白宫", "美国");
        user.setHouse(house);
        return ResponseResult.SUCCESS().setData(user);
    }

    @PostMapping("/test-login")
    public ResponseResult testlogin(@RequestBody User user){
        log.info("username == >" + user.getUserName());
        log.info("password == >" + user.getPassword());
        return ResponseResult.SUCCESS("登录成功").setData(user);
    }
}
